package trans.model;

import org.apache.commons.lang.StringUtils;

import trans.model.base.BaseSaStateHis;
import trans.support.Constants;



public class SaStateHis extends BaseSaStateHis {
	private static final long serialVersionUID = 1L;
	
	public String getStateFromValue(){
		if(this.getSa() instanceof AirSa){
			return Constants.AIRSA_STATES.get(super.getStateFrom());
		}
		if(this.getSa() instanceof OceanSa){
			return Constants.OCEANSA_STATES.get(super.getStateFrom());
		}
		return "UNDEFIND";
	}
	
	public String getStateToValue(){
		if(this.getSa() instanceof AirSa){
			return Constants.AIRSA_STATES.get(super.getStateTo());
		}
		if(this.getSa() instanceof OceanSa){
			return Constants.OCEANSA_STATES.get(super.getStateTo());
		}
		return "UNDEFIND";
	}
	
	public static final int OCEANSA_STATUS_ARR = 110;
	public static final int OCEANSA_STATUS_NFD = 120;
	public static final int OCEANSA_STATUS_DLV = 130;
	
	public String getStateToDesc(){
		if(this.getSa() instanceof OceanSa){
			switch (this.getStateTo()) {
			case Constants.OCEANSA_STATUS_RBK:
				return "BOOKING RECEIVED";
			case Constants.OCEANSA_STATUS_OWW:
				return "ON THE WAY TO WAREHOUSE";
			case Constants.OCEANSA_STATUS_RCF:
				return "RECEIVE FREIGHT";
			case Constants.OCEANSA_STATUS_RCD:
				return "RECEIVE DOCUMENTS";
			case Constants.OCEANSA_STATUS_SAH:
				return " STORAGE AND HANDLING";
			case Constants.OCEANSA_STATUS_STP:
				return "SEND TO PORT";
			case Constants.OCEANSA_STATUS_WSR:
				return "WAITING FOR THE SECOND RELEASE";
			case Constants.OCEANSA_STATUS_SMP:
				return "SHIPMENT";
			case Constants.OCEANSA_STATUS_SAL:
				return "SAIL";
			case Constants.OCEANSA_STATUS_DDV:
				return "DOOR-TO-DOOR VANNING";
			case Constants.OCEANSA_STATUS_ARR:
				return "ARRIVAL";
			case Constants.OCEANSA_STATUS_NFD:
				return "NOTIFY CONSIGNEE";
			case Constants.OCEANSA_STATUS_DLV:
				return "DELIVERY";
			default:
				return "";
			}
		}
		if(this.getSa() instanceof AirSa){
			switch (this.getStateTo()) {
			case Constants.AIRSA_STATUS_RBK:
				return "BOOKING RECEIVED";
			case Constants.AIRSA_STATUS_OWW:
				return "ON THE WAY TO WAREHOUSE";
			case Constants.AIRSA_STATUS_RCF:
				return "RECEIVE FREIGHT";
			case Constants.AIRSA_STATUS_RCD:
				return "RECEIVE DOCUMENTS";
			case Constants.AIRSA_STATUS_SAH:
				return "STORAGE AND HANDLING";
			case Constants.AIRSA_STATUS_RFC:
				return "READY FOR CARRIAGE";
			case Constants.AIRSA_STATUS_DEP:
				return "FLIGHT DEPARTS";
			case Constants.AIRSA_STATUS_DLV:
				return "FLIGHT DLV";
			case Constants.AIRSA_STATUS_ARR:
				return "FLIGHT ARRIVED";
			case Constants.AIRSA_STATUS_NFD:
				return "NOTIFY CONSIGNEE";
			case Constants.AIRSA_STATUS_DEL:
				return "DELIVERY";
			default:
				return "";
			}
		}
		return "";
	}
	
	public String getShowImg(){
		if(super.getSa() instanceof AirSa){
			if(this.getStateTo() <= Constants.AIRSA_STATUS_DEP){
				return super.getSa().getGatway().getName() + ".png";
			}else{
					AirSa airSa = (AirSa)super.getSa();
					if(this.getStateTo() <= Constants.AIRSA_STATUS_DLV){
						if(StringUtils.isEmpty(airSa.getDlvPlace()) == false){
							return airSa.getDlvPlace() + ".png";
						}
					}
					if(StringUtils.isEmpty(airSa.getDestination()) == false){
						return airSa.getDestination() + ".png";
				}
			}
		}
		if(super.getSa() instanceof OceanSa){
			if(this.getStateTo() <= Constants.OCEANSA_STATUS_SAL){
				return super.getSa().getGatway().getName() + ".png";
			}else{
					OceanSa oceanSa = (OceanSa)super.getSa();
					if(StringUtils.isEmpty(oceanSa.getPlaceOfDelivery()) == false){
						return oceanSa.getPlaceOfDelivery() + ".png";
				}
			}
		}
		return "trans.gif";
		
	}
	
	

/*[CONSTRUCTOR MARKER BEGIN]*/
	public SaStateHis () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public SaStateHis (java.lang.Integer id) {
		super(id);
	}

/*[CONSTRUCTOR MARKER END]*/


}